﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

namespace PC_Client
{
    public partial class Whisper : Form
    {
        private string _hostAndPort = string.Empty;
        private readonly Unit _unit = new Unit();
        private readonly Socket _clientSocket = null;

        public Whisper(string hostAndPort, Socket socket)
        {
            InitializeComponent();
            _hostAndPort = hostAndPort;
            _clientSocket = socket;
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            string whisperMsg = txtSendMsg.Text;
            if (string.IsNullOrEmpty(whisperMsg))
                MessageBox.Show("发送内容不能为空");

            MessagePackage mp = new MessagePackage() { ConnectType = (int)ConnectType.WhisperMsg, Msg = _hostAndPort + ";" + whisperMsg };
            _unit.MsgSend = Encoding.UTF8.GetBytes(JsonSerializer<MessagePackage>.GetObjectToJson(mp));

            _clientSocket.Send(_unit.MsgSend);
            this.txtSendMsg.Text = string.Empty;
        }
    }
}
